#include<bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO
{
	char buff[1<<21],*p1=buff,*p2=buff;
	char getch(){return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;}
	template<typename T>void read(T &x){char CH=getch();int fl=1;x=0;while(CH>'9'||CH<'0'){if(CH=='-')fl=-1;CH=getch();}while(CH<='9'&&CH>='0'){x=x*10+CH-48;CH=getch();}x*=fl;}
	template<typename T>void read_s(T &x){x="";char CH=getch();while(!(CH>='a'&&CH<='z')&&!(CH>='A'&&CH<='Z'))CH=getch();while((CH>='a'&&CH<='z')||(CH>='A'&&CH<='Z')){x+=CH;CH=getch();}}
	template<typename T,typename ...Args>void read(T &x,Args& ...args){read(x);read(args...);}
	char obuf[1<<21],*p3=obuf;
	void putch(char CH) {if(p3-obuf<(1<<21))*p3++=CH;else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=CH;}
	char CH[100];
	template<typename T>void write(T x) {if(!x)return putch('0');if(x<0)putch('-'),x*=-1;int top=0;while(x)CH[++top]=x%10+48,x/=10;while(top)putch(CH[top]),top--;}
	template<typename T,typename ...Args>void write(T x,Args ...args) {write(x);putch(' ');write(args...);}
	void put(string s){for(int i=0;i<s.size();i++)putch(s[i]);}
	void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
struct node
{
	int nxt,to,val;
}e[200005<<1];
int head[200005],cnt_edge;
void add_edge(int u,int v,int w)
{
	e[++cnt_edge].to=v;
	e[cnt_edge].val=w;
	e[cnt_edge].nxt=head[u];
	head[u]=cnt_edge;
}
int n,m;
#define pii pair<int,int>
#define fi first
#define se second
struct Shiroha
{
	struct segt
	{
		int l,r,val;
	}t[200005*20];
	#define mid (l+r>>1)
	int rt[200005],cnt;
	int insert(int x,int root,int l=1,int r=n)
	{
		int cur=++cnt;t[cur]=t[root];
		++t[cur].val;
		if(l==r) return cur;
		if(x<=mid) t[cur].l=insert(x,t[cur].l,l,mid);
		else t[cur].r=insert(x,t[cur].r,mid+1,r);
		return cur;
	}
	int query(int x,int y,int rtx,int rty,int l=1,int r=n)
	{
		if(x>y) return 0;
		if(l>=x&&r<=y) return t[rty].val-t[rtx].val;
		int res=0;
		if(x<=mid) res+=query(x,y,t[rtx].l,t[rty].l,l,mid);
		if(y>mid) res+=query(x,y,t[rtx].r,t[rty].r,mid+1,r);
		return res;
	}
	int kth(int k,int rtx,int rty,int l=1,int r=n)
	{
		if(l==r) return l;
		int cnt=t[t[rty].l].val-t[t[rtx].l].val;
		if(cnt>=k) return kth(k,t[rtx].l,t[rty].l,l,mid);
		return kth(k-cnt,t[rtx].r,t[rty].r,mid+1,r);
	}
}T[2];
int f[200005],son[200005],top[200005],siz[200005],dfn[200005],dep[200005],cnt,id[200005];
ll dis[200005];
void dfs1(int u,int fa)
{
	f[u]=fa;siz[u]=1;dep[u]=dep[fa]+1;
	dfn[u]=++cnt;id[cnt]=u;
	T[0].rt[dfn[u]]=T[0].insert(u,T[0].rt[dfn[u]-1]);
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		if(v==fa) continue;
		dis[v]=dis[u]+e[i].val;
		dfs1(v,u);siz[u]+=siz[v];
		if(siz[son[u]]<siz[v]) son[u]=v;
	}
}
void dfs2(int u,int t)
{
	top[u]=t;
	if(son[u]) dfs2(son[u],t);
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		if(v==f[u]||v==son[u]) continue;
		dfs2(v,v);
	}
}
inline int lca(int x,int y)
{
	for(;top[x]!=top[y];x=f[top[x]]) if(dep[top[x]]<dep[top[y]]) swap(x,y);
	return dep[x]<dep[y]?x:y;
}
inline ll calc(int x,int y){return dis[x]+dis[y]-2*dis[lca(x,y)];}
namespace Shiki
{
	pii st_mx[200005][20],st_mn[200005][20];
	int lg[200005];
	void bld()
	{
		for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
		for(int i=1;i<=n;i++) st_mx[i][0]=st_mn[i][0]={dfn[i],i};
		for(int j=1;j<20;j++)
			for(int i=1;i+(1<<j)-1<=n;i++) 
			{
				st_mx[i][j]=max(st_mx[i][j-1],st_mx[i+(1<<j-1)][j-1]);
				st_mn[i][j]=min(st_mn[i][j-1],st_mn[i+(1<<j-1)][j-1]);
			}
	}
	inline pii qmn(int l,int r){int k=lg[r-l+1];return min(st_mn[l][k],st_mn[r-(1<<k)+1][k]);}
	inline pii qmx(int l,int r){int k=lg[r-l+1];return max(st_mx[l][k],st_mx[r-(1<<k)+1][k]);}
}using namespace Shiki;
int main()
{
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	read(n,m);
	for(int i=1;i<n;i++)
	{
		int u,v,w;read(u,v,w);
		add_edge(u,v,w);add_edge(v,u,w);
	}
	dfs1(1,0);dfs2(1,1);
	bld();
	for(int i=1;i<=n;i++) T[1].rt[i]=T[1].insert(dfn[i],T[1].rt[i-1]);
	ll lastans=0;
	while(m--)
	{
		ll p,l,r;read(p,l,r);
		p^=lastans,l^=lastans,r^=lastans;
		if(p>=l&&p<=r){write(lastans=0),putch('\n');continue;}
		int lc=lca(qmn(l,r).se,qmx(l,r).se);
		int sz=T[0].query(l,r,T[0].rt[dfn[p]-1],T[0].rt[dfn[p]+siz[p]-1]);
		if(sz&&sz<r-l+1){write(lastans=0),putch('\n');continue;}
		if(dfn[lc]+siz[lc]-1>=dfn[p]&&dfn[p]>=dfn[lc])
		{
			int rk=T[1].query(1,dfn[p],T[1].rt[l-1],T[1].rt[r]);
			pii pos={0,0};
			int tmp=lca(id[T[1].kth(rk,T[1].rt[l-1],T[1].rt[r])],p);
			pos=max(pos,{dep[tmp],tmp});
			if(rk<r-l+1)
			{
				int tmp=lca(id[T[1].kth(rk+1,T[1].rt[l-1],T[1].rt[r])],p);
				pos=max(pos,{dep[tmp],tmp});
			}
			write(lastans=calc(pos.se,p)),putch('\n');
		}
		else write(lastans=calc(lc,p)),putch('\n');
	}
	flush();
	return 0;
}
